#
# @lc app=leetcode.cn id=101 lang=python3
#
# [101] 对称二叉树
#
from typing import Optional


class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
# @lc code=start
# Definition for a binary tree node.

class Solution:
    def isSymmetric(self, root: Optional[TreeNode]) -> bool:
        if root is None:
            return True
        return self.help(root.left, root.right)
    
    def help(self, node1: TreeNode, node2: TreeNode) -> bool:
        if node1 is None and node2 is None:
            return True
        if node1 is None or node2 is None:
            return False
        # 这里后面两个结点都不会为None了
        if node1.val != node2.val:
            return False
        return self.help(node1.left, node2.right) and self.help(node1.right, node2.left)

# @lc code=end

